<?php
/*
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2019 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class crm_customer_controller extends adminCommon{
	
    function set_search(){
        
        $cacheM     =   $this->MODEL('cache');
        
        $crmCache   =   $cacheM -> GetCache(array('crm'));
        
        $this->yunset(array('cache'=>$crmCache,'crmClassName' => $crmCache['crmclass_name'], 'crmStatus' => $crmCache['crmdata']['client_status'], 'crmType' => $crmCache['crmdata']['client_type']));
        
        $yyzz       =   array('1'=>'已认证', '2'=>'待审核', '3'=>'未通过', '4' => '待认证');
        
        $ratingM    =   $this -> MODEL('rating');
        $ratingArr  =   $ratingM -> getList(array( 'category' => '1', 'orderby' => 'sort' ), array('field'=>'`id`,`name`'));
        $vipEtime   =   array('1'=>'三天内', '2'=>'七天内', '3'=>'一月内', '4' => '已到期');
        
        $orders     =   array('1'=>'客户ID','2'=> '更新日期', '3'=>'VIP到期时间');
        
        $lastFtime  =   array('1'=>'从未联系', '2'=>'今天', '3'=>'三天未联系', '4'=>'七天未联系', '5'=>'一月未联系', '6'=>'一百天未联系');
        $nextFtime  =   array('1'=>'今天', '2'=>'明天', '3'=>'三天内', '4'=>'七天内', '5'=>'一月内');
        
        $this -> yunset(array('yyzzStatus' => $yyzz, 'ratingArr' => $ratingArr, 'vipEtime' => $vipEtime, 'orders' => $orders, 'lastFtime' => $lastFtime, 'nextFtime' => $nextFtime));
       
        //提取顾问信息
        $adminM    =   $this->MODEL('admin');
        $powerList =   $adminM -> getAdminGroupList(array('group_power' => array('like','219')), array('field' => '`id`'));
        
        if ($powerList) {
            $mids  =   array();
            foreach ($powerList as $v){
                $mids[]    =   $v['id'];
            }
        }
        
        $crmUser   =   $adminM -> getList(array('m_id' => array('in', pylode(',', $mids))));
        $this -> yunset('crmUser',$crmUser);
       
        $this->yunset('todayEnd', strtotime('tomorrow'));
    }
    
    function index_action(){
        
        $this -> set_search();
        
        $comM       =   $this -> MODEL('company');
        $userInfoM  =   $this -> MODEL('userinfo');
        $crmM       =   $this -> MODEL('crm');
        
        if ($_GET['self'] == '1') {
            
            $adminM =   $this->MODEL('admin');
            
            $power    =  $adminM -> getPower(array('uid'=>$_SESSION['auid']));
            
            $this ->  yunset('power', $power['power']);
                
            $where['crm_uid']   =   $_SESSION['auid'];
             
			$urlarr['self']     =   $_GET['self'];
            
            $this -> yunset('self', '1');
            
        }else{
            
            $where['crm_uid']   =   '0';
            
        }
        
        if (!empty($_GET['crm_status'])) {
            
            $crm_status =   intval($_GET['crm_status']);
            
            $where['crm_status']    =   $crm_status;
            
            $urlarr['crm_status']   =   $crm_status;
        }
        
        
        if (!empty($_GET['crmType'])) {
            
            $crmType =   intval($_GET['crmType']);
            
            $where['crm_type']    =   $crmType;
            
            $urlarr['crmType']   =   $crmType;
        }
        
        if (!empty($_GET['yyzz_status'])) {
            
            $yyzz_status            =   intval($_GET['yyzz_status']);
            
            if ($yyzz_status == 1) {
                
                $where['yyzz_status']   =   $yyzz_status;
                
            }else if ($yyzz_status == 4) {
                
                $where['yyzz_status']   =   0;
                
            }else {
                
                if ($yyzz_status == 2) {
                    
                    $certWhere  =   array('type' => 3, 'status' => 0);
                    
                }elseif ($yyzz_status == 3){
                    
                    $certWhere  =   array('type' => 3, 'status' => 3);
                }
                
                $certList       =   $comM -> getCertList($certWhere, array('field' => '`uid`'));
                
                $uidArrA        =   array();
                
                foreach ($certList as $cv){
                    $uidArrA[]  =   $cv['uid'];
                }
                
                $where['uid']   =   array('in', pylode(',', $uidArrA));
                
            }
            
            $urlarr['yyzz_status']  =   $yyzz_status;
        }
        
        if (!empty($_GET['rating'])) {
            
            $rating             =   intval($_GET['rating']);
            
            $where['rating']    =   $rating;
            
            $urlarr['rating']   =   $rating;
        }
        
        if (!empty($_GET['vipetime'])) {
            
            $etime  =   intval($_GET['vipetime']);
            
            if ($etime != 4) {
             
                if ($etime == 1) {
                    $num    =   '+3 day';
                }else if ($etime == 2) {
                    $num    =   '+7 day';
                }elseif ($etime == 3){
                    $num    =   '+1 month';
                }
                   
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['vipetime'][]        =   array('>', time(),'AND');
                $where['vipetime'][]        =   array('<', strtotime($num),'AND');
                $where['PHPYUNBTWEND_A']    =   '';
                
            }else{
                
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['vipetime'][]        =   array('<', strtotime(date('Y-m-d')), 'AND');
                $where['vipetime'][]        =   array('>', '0', 'AND');
                $where['PHPYUNBTWEND_A']    =   '';
            }
            
            $urlarr['vipetime'] =   $etime;
            
        }
        
        if (!empty($_GET['regStart']) || !empty($_GET['regEnd'])) {
            
            $regStart   =   strtotime($_GET['regStart']);
            $regEnd     =   strtotime($_GET['regEnd']);
            
            $mWhere['PHPYUNBTWSTART_A']     =   '';
            $mWhere['reg_date'][]           =   array('>', $regStart, 'AND');
            $mWhere['reg_date'][]           =   array('<', $regEnd, 'AND');            
            $mWhere['PHPYUNBTWEND_A']       =   '';
            
            $memberList     =   $userInfoM -> getList($mWhere, array('field' => 'uid'));
            
            $uidArrB        =   array();
            foreach ($memberList as $mv) {
                $uidArrB[]  =   $mv['uid'];
            }
            
            $where['uid']   =   array('in', pylode(',', $uidArrB));
             
            $urlarr['regStart'] =   $_GET['regStart'];
            $urlarr['regEnd']   =   $_GET['regEnd'];
        }
        
        if (!empty($_GET['lastFtime'])) {
            
            $lastFtime  =   intval($_GET['lastFtime']);
            
            if ($lastFtime == 1) {
                
                $where['isfollow']  =   '0';
            }else {
                                
                $cWhere['uid']  =   $_SESSION['auid'];
                
                $comList        =   $comM -> getList(array('crm_uid' => $_SESSION['auid'], 'isfollow' => 1), array('field' => '`uid`'));
                
                $uidArrL        =   array();
                
                foreach ($comList['list'] as $clv) {
                    
                    $uidArrL[]  =   $clv['uid'];
                }
                
                $cWhere['uid']    =   array('in', pylode(',', $uidArrL));
                
                
                if ($lastFtime == 2){   
                
                    $cWhere['atime']    =   array('>', strtotime(date('Y-m-d')));
                }elseif ($lastFtime == 3){
                    
                    $cWhere['atime']    =   array('<', strtotime('-3 day'));
                }elseif ($lastFtime == 4){
                    
                    $cWhere['atime']    =   array('<', strtotime('-7 day'));
                }elseif ($lastFtime == 5){
                    
                    $cWhere['atime']    =   array('<', strtotime('-1 month'));
                }elseif ($lastFtime == 6){
                    
                    $cWhere['atime']    =   array('<', strtotime('-100 day'));
                }
                
                $concernList            =   $crmM -> getConcernList($cWhere, array('field' => '`uid`'));
                
                $uidArrLa       =   array();
                
                foreach ($concernList as $conV) {
                    $uidArrLa[] =   $conV['uid'];
                }
                
                $uidArrL        =   $uidArrLa;
                
                $where['uid']   =   array('in', pylode(',', $uidArrL));
            }
            
            $urlarr['lastFtime']    =   $lastFtime;
        }   
        
        if (!empty($_GET['nextFtime'])) {
            
            $nextFtime  =   intval($_GET['nextFtime']);
            
            $taskWhere  =   array();
            
            if($nextFtime == 1){
                
                $taskWhere['stime']             =   array('<', strtotime(date('Y-m-d 23:59:59')));  //  之前未完成的跟进同步显示
            }elseif ($nextFtime == 2){
                
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', strtotime(date('Y-m-d 23:59:59')));
                $taskWhere['stime'][]           =   array('<', strtotime(date('Y-m-d 23:59:59')) + 86400);
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            }elseif ($nextFtime == 3){
                
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', time());
                $taskWhere['stime'][]           =   array('<', strtotime('+3 day'));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            }elseif ($nextFtime == 4){
                
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', time());
                $taskWhere['stime'][]           =   array('<', strtotime('+1 week'));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            }elseif ($nextFtime == 5){
                
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', time());
                $taskWhere['stime'][]           =   array('<', strtotime('+1 month'));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            }
            
            $taskWhere['uid']   =   $_SESSION['auid'];
            
            $taskList   =   $crmM -> getTaskList($taskWhere, array('field' => '`comid`'));
            
            $uidArrN    =   array();
            foreach ($taskList as $tv) {
                
                $uidArrN[]  =   $tv['comid'];
            }
            
            $where['uid']   =   array('in', pylode(',', $uidArrN));
        }
        
         
        if ($_GET['keyword']) {
            
            $keywordStr     =   trim($_GET['keyword']);
            
            $typeStr        =   intval($_GET['crm_type']);
            
            if (!empty($keywordStr)) {
                
                if ($typeStr == 1) {
                    
                    $where['name']      =   array('like', $keywordStr);
                    
                }else if($typeStr == 2){
                    
                    $where['linkman']   =   array('like', $keywordStr);
                    
                }else if($typeStr == 3){
                    
                    $where['linktel']   =   array('like', $keywordStr);
                    
                }else if($typeStr == 4){
                    
                    $where['uid']       =   array('like', $keywordStr);
                }
                
            }
            $urlarr['crm_type']	    =	$typeStr;
            $urlarr['keyword']		=	$keywordStr;
        }
        
        if (!empty($_GET['ordertype'])) {
            
            $orderType  = intval($_GET['ordertype']);
            
            if ($orderType == 1) {
                $order  =   'uid';
            }else if ($orderType == 2) {
                $order  =   'lastupdate';
            }else if ($orderType == 3) {
                $order  =   'vipetime';
            }
            
            $urlarr['ordertype']    =   $orderType;
        }else{
            $where['orderby']    =   'uid,DESC';
        }
        
        
        $urlarr['page']	    =	'{{page}}';
        
        $pageurl            =	Url($_GET['m'], $urlarr, 'admin');
        
        $pageM              =	$this  -> MODEL('page');
        
        $pages              =	$pageM -> pageList('company', $where, $pageurl, $_GET['page']);
        
        if ($pages['total'] > 0) {
            
            if ($_GET['order']) {
                
                if ($_GET['t']) {
                    
                    $where['orderby']   =   $_GET['t'].','.$_GET['order'];
                    $urlarr['t']        =   $_GET['t'];
                }else if($order){
                    
                    $where['orderby']   =   $order.','.$_GET['order'];
                }else{
                    
                    $where['orderby']   =   'uid';
                }
                
                $urlarr['order']    =   $_GET['order'];
            } 
            
            $where['limit']         =   $pages['limit'];
            
            $listA                  =   $comM -> getList($where,array('utype' => 'crm'));
            $this -> yunset(array('rows' => $listA['list'],'auid' => intval($_SESSION['auid'])));
        } 
        
        
        /**
         * @desc 今日跟进任务 ;今日需跟进客户数量
         */
        $toWhere        =   array(
            'uid'   =>  intval($_SESSION['auid']),
            'type'  =>  '22',
            'status'=>  '1',
            'stime' =>  array('<', strtotime(date('Y-m-d 23:59:59')))
        );
        $toFollowList   =   $crmM -> getTaskList($toWhere, array('field' => '`comid`'));
        
        $toUids =   array();
        foreach ($toFollowList as $toV) {
            $toUids[$toV['comid']]  =   $toV['comid'];
        }
        $todayNum   =   count($toUids) > 0 ? count($toUids) : 0;  
        
        /**
         * @desc 跟进期限内未跟进客户数量 【期限参数：sy_crm_follow_deadline】
         */
        if ((int)$this->config['sy_crm_follow_deadline'] > 0) {
            
            $noFollowDeadList   =   $crmM -> getConcernList(array('auid' => intval($_SESSION['auid']), 'atime' => array('<', strtotime('- '.$this->config['sy_crm_follow_deadline'].' day'))), array('field' => '`uid`'));
           
            $noFollowUids   =   array();
            foreach ($noFollowDeadList as $noV) {
                $noFollowUids[$noV['uid']] = $noV['uid'];
            }
            $noNum1 =   count($noFollowUids) > 0 ? count($noFollowUids) : 0;    //  跟进后查过期限未跟进客户
            
            $noNum2 =   $comM -> getCompanyNum(array('crm_uid' => $_SESSION['auid'], 'isfollow' => '0', 'crm_time' => array('<', strtotime('- '.$this->config['sy_crm_follow_deadline'].' day')))); // 超期限从未跟进
            
            $noFollowNum    =   $noNum1 + $noNum2;
        }
        $this -> yunset(array('todayNum' => $todayNum, 'noFollowNum' => $noFollowNum));
        
        $AdminM			=	$this -> MODEL('admin');
		$adminUserList	=	$AdminM -> getList(array(),array('field'=>'`uid`,`name`'));
		$this->yunset('adminUserList',$adminUserList);
		$this -> yuntpl(array('admin/crm_customer'));
    }
    
    /**
     * @desc crm - 下属的客户
     */
    function depart_action(){
		$this -> set_search();
        $AdminM			=	$this -> MODEL('admin');
		$Company		=	$this -> MODEL('company');
		$userInfoM  	=   $this -> MODEL('userinfo');
		$crmM       	=   $this -> MODEL('crm');
        $adminUserInfo	=	$AdminM -> getAdminUser(array('uid' => $_SESSION['auid']),array('field'=>'depart'));
		$adminUserList	=	$AdminM -> getList(array('uid'=>array('<>',$_SESSION['auid']),'depart'=>$adminUserInfo['depart']),array('field'=>'`uid`,`name`,`username`'));
		foreach($adminUserList as $v){
			$uids[]		=	$v['uid'];
		}
		$this->yunset('adminUserList',$adminUserList);
		if(!empty($_GET['crmType'])) {           
            $crmType			=	intval($_GET['crmType']);
            $where['crm_type']	=   $crmType; 
            $urlarr['crmType']	=   $crmType;
        }
		if(!empty($_GET['crm_status'])) {
            $crm_status				=   intval($_GET['crm_status']);
            $where['crm_status']	=   $crm_status;
            $urlarr['crm_status']	=   $crm_status;
        }
		if(!empty($_GET['yyzz_status'])) {  
            $yyzz_status	=	intval($_GET['yyzz_status']);
            if ($yyzz_status == 1) { 
                $where['yyzz_status']	=	$yyzz_status; 
            }else if ($yyzz_status == 4) {  
                $where['yyzz_status']	=	0;
            }else {
                if ($yyzz_status == 2) { 
                    $certWhere  =   array('type' => 3, 'status' => 0);     
                }elseif ($yyzz_status == 3){            
                    $certWhere  =   array('type' => 3, 'status' => 3);
                }          
                $certList       =   $Company -> getCertList($certWhere, array('field' => '`uid`'));
                $uidArrA        =   array();       
                foreach ($certList as $cv){
                    $uidArrA[]  =   $cv['uid'];
                }           
                $where['uid']   =   array('in', pylode(',', $uidArrA));            
            }    
            $urlarr['yyzz_status']  =   $yyzz_status;
        }
		if(!empty($_GET['rating'])) {  
            $rating             =   intval($_GET['rating']);
            $where['rating']    =   $rating;
            $urlarr['rating']   =   $rating;
        }
		if(!empty($_GET['regStart']) || !empty($_GET['regEnd'])) { 
            $regStart   =   strtotime($_GET['regStart']);
            $regEnd     =   strtotime($_GET['regEnd']); 
            $mWhere['PHPYUNBTWSTART_A']     =   '';
            $mWhere['reg_date'][]           =   array('>', $regStart, 'AND');
            $mWhere['reg_date'][]           =   array('<', $regEnd, 'AND');            
            $mWhere['PHPYUNBTWEND_A']       =   '';
            $memberList     =   $userInfoM -> getList($mWhere, array('field' => 'uid'));            
            $uidArrB        =   array();
            foreach ($memberList as $mv) {
                $uidArrB[]  =   $mv['uid'];
            }   
            $where['uid']   =   array('in', pylode(',', $uidArrB));   
            $urlarr['regStart'] =   $_GET['regStart'];
            $urlarr['regEnd']   =   $_GET['regEnd'];
        }
		if(!empty($_GET['ordertype'])) {  
            $orderType	=	intval($_GET['ordertype']); 
            if ($orderType == 1) {
                $order  =   'uid';
            }else if ($orderType == 2) {
                $order  =   'lastupdate';
            }else if ($orderType == 3) {
                $order  =   'vipetime';
            }
            $urlarr['ordertype']    =   $orderType;
        }
		if(!empty($_GET['lastFtime'])) {  
            $lastFtime  =   intval($_GET['lastFtime']);
            if ($lastFtime == 1) {  
                $where['isfollow']  =   '0';
            }else {                 
                $cWhere['uid']  =   $_SESSION['auid'];
                $comList        =   $Company -> getList(array('crm_uid' => $_SESSION['auid'], 'isfollow' => 1), array('field' => '`uid`'));
                $uidArrL        =   array();
                foreach ($comList['list'] as $clv) {
                    $uidArrL[]  =   $clv['uid'];
                }
                $cWhere['uid']	=	array('in', pylode(',', $uidArrL));
                if ($lastFtime == 2){   
                    $cWhere['atime']	=	array('>', strtotime(date('Y-m-d')));
                }elseif ($lastFtime == 3){
                    $cWhere['atime']    =   array('<', strtotime('-3 day'));
                }elseif ($lastFtime == 4){ 
                    $cWhere['atime']    =   array('<', strtotime('-7 day'));
                }elseif ($lastFtime == 5){
                    $cWhere['atime']    =   array('<', strtotime('-1 month'));
                }elseif ($lastFtime == 6){
                    $cWhere['atime']    =   array('<', strtotime('-100 day'));
                }
                $concernList            =   $crmM -> getConcernList($cWhere, array('field' => '`uid`'));
                $uidArrLa       =   array();
                foreach ($concernList as $conV) {
                    $uidArrLa[] =   $conV['uid'];
                } 
                $uidArrL        =   $uidArrLa; 
                $where['uid']   =   array('in', pylode(',', $uidArrL));
            }
            $urlarr['lastFtime']    =   $lastFtime;
        }  
		if(!empty($_GET['nextFtime'])) { 
            $nextFtime  =   intval($_GET['nextFtime']);
            $taskWhere  =   array();
            if($nextFtime == 1){ 
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', strtotime(date('Y-m-d')));
                $taskWhere['stime'][]           =   array('<', strtotime(date('Y-m-d 23:59:59')));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            }elseif ($nextFtime == 2){
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', strtotime(date('Y-m-d 23:59:59')));
                $taskWhere['stime'][]           =   array('<', strtotime(date('Y-m-d 23:59:59')) + 86400);
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            }elseif ($nextFtime == 3){
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', time());
                $taskWhere['stime'][]           =   array('<', strtotime('+3 day'));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            }elseif ($nextFtime == 4){
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', time());
                $taskWhere['stime'][]           =   array('<', strtotime('+1 week'));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            }elseif ($nextFtime == 5){ 
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', time());
                $taskWhere['stime'][]           =   array('<', strtotime('+1 month'));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            }
            $taskWhere['uid']   =   $_SESSION['auid'];
            $taskList   =   $crmM -> getTaskList($taskWhere, array('field' => '`comid`'));
            $uidArrN    =   array();
            foreach ($taskList as $tv) {  
                $uidArrN[]  =   $tv['comid'];
            }
            $where['uid']   =   array('in', pylode(',', $uidArrN));
        }	
		if(!empty($_GET['vipetime'])) { 
            $etime  =   intval($_GET['vipetime']);
            if ($etime != 4) {
                if ($etime == 1) {
                    $num    =   '+3 day';
                }else if ($etime == 2) {
                    $num    =   '+7 day';
                }elseif ($etime == 3){
                    $num    =   '+1 month';
                }
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['vipetime'][]        =   array('>', time(),'AND');
                $where['vipetime'][]        =   array('<', strtotime($num),'AND');
                $where['PHPYUNBTWEND_A']    =   '';
            }else{ 
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['vipetime'][]        =   array('<', strtotime(date('Y-m-d')), 'AND');
                $where['vipetime'][]        =   array('>', '0', 'AND');
                $where['PHPYUNBTWEND_A']    =   '';
            }
            $urlarr['vipetime'] =   $etime;
        }
		if(!empty($_GET['crmmanager'])) {
			$where['crm_uid']		=	$_GET['crmmanager'];
            $urlarr['crmmanager']	=   $_GET['crmmanager'];
        }else{
            $where['PHPYUNBTWSTART_A']  =   '';
            $where['crm_uid'][]	        =	array('<>',0,'AND');
            $where['crm_uid'][]	        =	array('in',pylode(',',$uids),'AND');
            $where['PHPYUNBTWEND_A']    =   '';
        }
		$urlarr['page']	    =	'{{page}}';    
        $pageurl            =	Url('crm_customer&c=depart', $urlarr, 'admin');    
        $pageM              =	$this  -> MODEL('page');      
        $pages              =	$pageM -> pageList('company', $where, $pageurl, $_GET['page']);  
	    if ($pages['total'] > 0) {  
            if ($_GET['order']) {               
                if ($_GET['t']) {                
                    $where['orderby']   =   $_GET['t'].','.$_GET['order'];
                    $urlarr['t']        =   $_GET['t'];
                }else if($order){          
                    $where['orderby']   =   $order.','.$_GET['order'];
                }else{              
                    $where['orderby']   =   'uid';
                }           
                $urlarr['order']    =   $_GET['order'];
            }     
            $where['limit']         =   $pages['limit'];    
            $comList                 =   $Company -> getList($where,array('utype' => 'crm'));
            $this -> yunset('rows',$comList['list']);
        }
        $this -> yuntpl(array('admin/crm_customer_depart'));
    }
	
	
	/**
	 * @desc CRM - 录客户
	 */
	function add_action(){
	    
	    if ($_POST['submit']) {
	        
 	        $mPost = array(
 	            'username' =>  trim($_POST['username']),
 	            'moblie'   =>  trim($_POST['moblie']),
 	            'email'    =>  trim($_POST['email'])
 	        );
 	        
	        if($_POST['username'] =='' || mb_strlen($_POST['username']) < 2 || mb_strlen($_POST['username']) > 16){
	            
	            $this -> ACT_layer_msg('客户名称格式错误',8);
	            
	        }elseif($_POST['password']==''||mb_strlen($_POST['password'])<6||mb_strlen($_POST['password'])>20){
	            
	            $this -> ACT_layer_msg('客户账号格式错误',8);
	            
	        }
	        
	        $userinfoM  =  $this -> MODEL('userinfo');
	        
	        $result  =  $userinfoM -> addMemberCheck($mPost);
	        
	        if ($result['msg']){
	            
	            $this -> ACT_layer_msg($result['msg'],8);
	        }
	        
	        if($this->config['sy_uc_type']=='uc_center'){
	            
	            $this -> obj-> uc_open();
	            
	            $user  =  uc_get_user($_POST['username']);
	            
	            if(is_array($user)){
	                
	                $this -> ACT_layer_msg('该会员已经存在！',8);
	                
	            }
	            
	        }
	        $time  =  time();
	        $ip    =  fun_ip_get();
	        $pass  =  $_POST['password'];
	        
	        if($this->config['sy_uc_type'] == 'uc_center'){
	            
	            $uid  =  uc_user_register($_POST['username'],$pass,$_POST['email']);
	            
	            if($uid < 0){
	                
	                switch($uid){
	                    
	                    case '-1' : $data['msg']='用户名不合法!';
	                    break;
	                    case '-2' : $data['msg']='包含不允许注册的词语!';
	                    break;
	                    case '-3' : $data['msg']='用户名已经存在!';
	                    break;
	                    case '-4' : $data['msg']='Email 格式有误!';
	                    break;
	                    case '-5' : $data['msg']='Email 不允许注册!';
	                    break;
	                    case '-6' : $data['msg']='该 Email 已经被注册!';
	                    break;
	                }
	                
	                $this -> ACT_layer_msg($data['msg'],8);
	                
	            }else{
	                
	                list($uid, $username, $email, $password, $salt)    =   uc_get_user($_POST['email'], $pass);
	                
	            }
	        }else{
	            $pwdRes    =   $userinfoM -> generatePwd(array('password' => $pass));
	            
	            $salt      =  $pwdRes['salt'];
	            $password  =  $pwdRes['pwd'];
	            
	        }
	        
	        $mdata = array(
	            
	            'username'  =>  trim($_POST['username']),
	            'password'  =>  $password,
	            'usertype'  =>  2,
	            'salt'      =>  $salt,
	            'address'   =>  $_POST['address'],
	            'moblie'    =>  $_POST['moblie'],
	            'email'     =>  $_POST['email'],
	            'reg_date'  =>  $time,
	            'reg_ip'    =>  $ip,
	            'source'    =>  '16', 
	            'status'    =>  1
	            
	        );
	        
	        if($_POST['areacode'] && $_POST['telphone']){
	            
	            $_POST['phone'] =   $_POST['areacode'].'-'.$_POST['telphone'];
	            
	            if($_POST['exten']){
	                
	                $_POST['phone'] .= '-'.$_POST['exten'];
	                
	            }
	        }
	        
	        $udata = array(
	            
	            'name'         =>  $_POST['name'],
	            'hy'           =>  $_POST['hy'],
	            'provinceid'   =>  $_POST['provinceid'],
	            'cityid'       =>  $_POST['cityid'],
	            'three_cityid' =>  $_POST['three_cityid'],
	            'address'      =>  $_POST['address'],
	            'linkman'      =>  $_POST['linkman'],
	            'linktel'      =>  $_POST['moblie'],
	            'linkphone'    =>  $_POST['phone'],
	            'linkmail'     =>  $_POST['email'],
	            'crm_uid'      =>  $_SESSION['auid'],
	            'crm_time'     =>  $time,
	            'crm_type'     =>  $_POST['crm_type'],
	            'crm_status'   =>  $_POST['crm_status']
	            
	        );
	        
	        $sdata = array(
	            
	            'rating'       =>  $this -> config['com_rating']
	            
	        );
	        
	        $nid   =   $userinfoM -> addInfo(array('mdata' => $mdata,'udata' => $udata, 'sdata' => $sdata));
	        
	        if ($nid) {
	            
	            $crmM          =   $this -> MODEL('crm');
	            
	            if ($_POST['crm_status'] == '9' && !empty($_POST['rating_name'])) {   // 成单客户，新建订单（待审核）
	                
	                $dealData  =   array(
	                    
	                    'uid'      =>  $nid,
	                    'rating'   =>  intval($_POST['rating_name']),
	                    'crm_uid'  =>  $_SERVER['auid']
	                    
	                );
	                
	               $crmM  -> addDeal($dealData);
	                
	            }
	            
	            /* if ($_POST['is_task'] == 'on') {   // 新建待办任务
	                
	                $taskData      =   array(
	                    
	                    'auid'     =>  $_SESSION['auid'],
	                    'uid'      =>  $_SESSION['auid'],
	                    'comid'    =>  $nid,
	                    'title'    =>  $_POST['title'],
	                    'content'  =>  $_POST['task_content'],
	                    'stime'    =>  $_POST['stime'],
	                    'priority' =>  $_POST['priority'],
    	                    
	                );
	                
	               $crmM -> addWaitingTask($taskData);
	                
	            } */
	            
	        }
 	        
	        $msg   =   $nid ? '客户（ID：'.$nid.'）新加成功！' : '客户新加失败，请重试！';      
	        
	        if($nid > 0){
	            
	            $this -> ACT_layer_msg($msg, 9, 'index.php?m=crm_customer&self=1');
	            
	        }else{
	            
	            $this -> ACT_layer_msg($msg, 8);
	        }
	        
	    }
	    
	    $ratingM   =   $this -> MODEL('rating');
	    
	    $rating    =   $ratingM -> getList(array('category' => '1', 'orderby' => 'sort,asc'), array('field' => '`id`,`name`'));
	    
	    $this  ->  yunset('rating_list',$rating);
	    
	    $cacheM    =   $this->MODEL('cache');
	    
	    $options   =   array('crm','hy','city');
	    
	    $cache     =   $cacheM -> GetCache($options);
	    
	    $this  ->  yunset('cache',  $cache);
	    
	    $this->yuntpl(array('admin/crm_customer_add'));
	    
	}
	
	/**
	 * @desc CRM - 新增客户 - 用户名检测
	 */
	function check_action() {
	    $username  =   trim($_POST['username']);
	    $userinfoM =   $this -> MODEL('userinfo');
	    
	    $check     =   $userinfoM -> addMemberCheck(array('username' => $username));
        	    
	    echo $check['msg'];die;
	}
	
	/**
	 * @desc CRM - 新建订单（业务员开通套餐，待审核）
	 */
	function getstatis_action(){
	    
	    $ratingM   =   $this -> MODEL('rating');
	    
	    $rating    =   $ratingM -> getList(array('category' => '1', 'orderby' => 'sort,asc'), array('field' => '`id`,`name`'));
	    
	    if(!empty($rating)){
	        
	        foreach($rating as $k => $v){
	        
	            $ratingarr[$v['id']]   =   $v['name'];
	        
	        }
	        
	    }
 	    
	    $this -> yunset('ratingarr',$ratingarr);
	    
	    if($_GET['uid']){
	        
	        $uid       =   intval($_GET['uid']);
	        
	        $statisM   =   $this -> MODEL('statis');
	        
	        $row       =   $statisM -> getInfo($uid, array('usertype' => '2'));
	        
	        if($row['vip_etime'] > 0){
	            
	            $row['vipetime']   =   date("Y-m-d",$row['vip_etime']);
	        
	        }else{
	            
	            $row['vipetime']   =   '不限';
	            
	        }
	        
	        $this->yunset('row',$row);
	    }
	    
	    $this->yuntpl(array('admin/crm_customer_rating'));
	    
	}
	
	/**
	 * @desc CRM - 开通套餐  -  选择套餐查询数据返回；
	 */
	function getrating_action(){
	    
	    if($_POST['id']){
	        
	        $id        =   intval($_POST['id']);   
	        
	        $ratingM   =   $this -> MODEL('rating');
	        
	        $rating    =   $ratingM -> getInfo(array('id' => $id, 'category' => '1'));
	        
	        if($rating['service_time'] > 0){
	            
	            $rating['vip_etime']   =   time()  +   $rating['service_time'] *   86400;
	            
	            $rating['vipetime']    =   date('Y-m-d', $rating['vip_etime']);
	        
	        }else{
	            
	            $rating['vip_etime']   =   0;
	            
	            $rating['vipetime']    =   '不限';
	        
	        }
	        
	        if($rating['time_start'] < time() && $rating['time_end'] > time()){
	            
	            $rating['price']       =   $rating['yh_price'];
	            
	        }else{
	            
	            $rating['price']       =   $rating['service_price'];
	        
	        }
	        
	        echo json_encode($rating);
	    }
	    
	}
	
	/**
	 * @desc 客户信息页面
	 */
	function com_action() {
	    
	    if ($_GET['id']) {
	        
	        $comM      =   $this -> MODEL('company');
	        $crmM      =   $this -> MODEL('crm');
	        
	        $ratingM   =   $this -> MODEL('rating');
	        $ratingArr =   $ratingM -> getList(array( 'category' => '1', 'orderby' => 'sort' ), array('field'=>'`id`,`name`'));
	        
	        
	        $cacheM    =   $this -> MODEL('cache');
	        
	        $crmCache  =   $cacheM -> GetCache(array('crm'));
	        
	        $this->yunset(array(
	            'cache'        =>  $crmCache,
	            'crmClassName' =>  $crmCache['crmclass_name'], 
	            'crmType'      =>  $crmCache['crmdata']['client_type'], 
	            'crmStatus'    =>  $crmCache['crmdata']['client_status'], 
	            'outClass'     =>  $crmCache['crmdata']['crm_outclass'],
	            'followWay'    =>  $crmCache['crmdata']['follow_way'],
	            'crmTaskType'  =>  $crmCache['crmdata']['task_type'],
	            'ratingArr'    =>  $ratingArr,
	            'ratinglist'   =>  $ratingArr
	        ));
	        
	        $comid     =   intval($_GET['id']);
	        
	        $type      =   $_GET['type'] ? intval($_GET['type']) : 1;
	        
	        $comInfo   =   $comM -> getInfo($comid, array('logo' => 1, 'crm' => 1, 'auid' => $_SESSION['auid']));
	        $this->yunset('Info', $comInfo);
	        
	        if (!empty($comInfo['followInfo'])) {
	            $this->yunset('followInfo', $comInfo['followInfo']);
	        }
	        
	        //提取顾问信息
	        $adminM    =   $this->MODEL('admin');
	        $powerList =   $adminM -> getAdminGroupList(array('group_power' => array('like','219')), array('field' => '`id`'));
	        
	        if ($powerList) {
	            $mids  =   array();
	            foreach ($powerList as $v){
	                $mids[]    =   $v['id'];
	            }
	        }
	        
	        $crmUser   =   $adminM -> getList(array('m_id' => array('in', pylode(',', $mids))));
	        $this -> yunset(array('crmUser' => $crmUser));
	        
	        
	        $pageM             =   $this  -> MODEL('page');
	        
	        //操作记录
	        $logWhere          =   $logUrlArr  =   array();
	        $logWhere['uid']   =   $comid;
	        $logUrlArr['page'] =   '{{page}}';
	        $logUrlArr['c']    =   'com';
	        $logUrlArr['id']   =   $comid;
	        $logUrlArr['type'] =   $type;
	        $pageurl           =   Url($_GET['m'], $logUrlArr, 'admin');
	        $pages             =   $pageM -> pageList('crm_comlog', $logWhere, $pageurl, $_GET['page']);
	        
	        if ($pages['total'] > 0) {
	            $logWhere['limit']     =   $pages['limit'];
	            $logWhere['orderby']   =   'ctime,desc';
	            $logList               =   $crmM -> getComLogList($logWhere, array('utype' => 'crm'));
	            $this->yunset(array('logList'=>$logList, 'logtotal'=>$pages['total'], 'logpagenav'=>$pages['pagenav'], 'loglimit'=>$pages['limit']));
	        }

	        // 联系跟进记录
	        $followUrlArr    =   $followWhere    =   array();
	        $followWhere['uid']    =   $comid;
	        $followUrlArr['page']  =   '{{page}}';
	        $followUrlArr['c']     =   'com';
	        $followUrlArr['id']    =   $comid;
	        $followUrlArr['type']  =   $type;
	        
	        if(!$_GET['all']){
	            $followWhere['auid']   =   $_SESSION['auid'];
	        }
	        
	        $fpageurl              =   Url($_GET['m'], $followUrlArr, 'admin');
	        $fpages                =   $pageM -> pageList('crmnew_concern', $followWhere, $fpageurl, $_GET['page'],'4');
	        if($fpages['total']>0){
	            $followWhere['limit']      =   $fpages['limit'];
	            $followWhere['orderby']    =   'atime,desc';
	            $followList     =   $crmM -> getConcernList($followWhere, array('utype' => 'crm'));
	            $this->yunset(array('followList'=>$followList, 'ftotal'=>$fpages['total'], 'fpagenav'=>$fpages['pagenav'], 'flimit'=>$fpages['limit']));
	        }
	        
	        // 开单记录
	        $orderM    =   $this->MODEL('companyorder');
	        $orUrlArr  =   $orWhere    =   array();
	        $orWhere['uid']    =   $comid;
	        $orWhere['crm_uid']=   $_SESSION['auid'];
	        
	        if(!empty($_GET['orState'])){
	            
	            $orWhere['order_state']    =   intval($_GET['orState']);
	            $orUrlArr['orState']       =   $_GET['orState'];
	        }
	        
	        if(!empty($_GET['orType'])){
	            $orWhere['order_type'] =   $_GET['orType'];
	            $orUrlArr['orType']    =   $_GET['orType'];
	        }
	        
	        if(!empty($_GET['orRating'])){
	            $orWhere['rating']     =   $_GET['orRating'];
	            $orUrlArr['orType']    =   $_GET['orRating'];
	        }
	        
	        if(!empty($_GET['orStime']) || !empty($_GET['orEtime'])){
	            
	            $orStime   =   strtotime($_GET['orStime']);
	            $orEtime   =   $_GET['orEtime'] ? (strtotime($_GET['orEtime']) + 86399) : time(); 
	            
	            $orWhere['PHPYUNBTWSTART_A']   =   '';
	            $orWhere['order_time'][]       =   array('>', $orStime,'AND');
	            $orWhere['order_time'][]       =   array('<', $orEtime ,'AND');
	            $orWhere['PHPYUNBTWEND_A']     =   '';
	        }
	        
	        if(!empty($_GET['orKeyword'])){   
	            $orWhere['order_id']   =   array('like', trim($_GET['orKeyword']));
	        }

	        $orUrlArr['page']  =   '{{page}}';
	        $orUrlArr['c']     =   'com';
	        $orUrlArr['id']    =   $comid;
	        $orUrlArr['type']  =   $type;
	        
	         
	        $orpageurl         =   Url($_GET['m'], $orUrlArr, 'admin');
	        $orpages           =   $pageM -> pageList('company_order', $orWhere, $orpageurl, $_GET['page']);
	        if($orpages['total']>0){
	            $orWhere['limit']      =   $orpages['limit'];
	            $orWhere['orderby']    =   'order_time,desc';
	            $orderList             =   $orderM -> getList($orWhere, array('utype' => 'crmdealsp'));
	            
	            $this->yunset(array('orderList'=>$orderList, 'orderTotal'=>$orpages['total'], 'orderpagenav'=>$orpages['pagenav'], 'orderlimit'=>$orpages['limit']));
	        }
	        
	        $this->yunset(array('auid' => $_SESSION['auid'], 'type' => $type));
	        
	    }
	    
	    $AdminM			=	$this -> MODEL('admin');
	    $adminUserList	=	$AdminM -> getList('',array('field'=>'`uid`,`name`'));
	    $this->yunset('adminUserList',$adminUserList);
	    
	    $this->yuntpl(array('admin/crm_com_info'));
	}
	
	/**
	 * @desc 转交客户
	 */
	function deliver_action()
    {
        if (!empty($_POST)) {

            
            $data           =   $_POST;
            $data['auid']   =   $_SESSION['auid'];
            
            $crmM           =   $this -> MODEL('crm');

            $return         =   $crmM -> deliverUser($data);
            
            echo json_encode($return);die;
            
        }
    }
    
    /**
     * @desc 放弃客户
     */
    function giveUp_action()
    {
        if (!empty($_POST)) {
            
            
            $data           =   $_POST;
            $data['auid']   =   $_SESSION['auid'];
            
            $crmM           =   $this -> MODEL('crm');
            
            $return         =   $crmM -> giveUpUser($data);
            
            echo json_encode($return);die;
            
        }
    }
    
    /**
     * @desc 修改客户状态/等级
     */
    function upStatusType_action()
    {
        if (!empty($_POST)) {
            
            $data           =   $_POST;
            
            $data['auid']   =   $_SESSION['auid'];
            
            $crmM           =   $this -> MODEL('crm');
            
            $return         =   $crmM -> upComST($data);
             
            echo json_encode($return);die;
            
        }
    }
    
    /**
     * @desc 修改客户联系方式
     */
    function upComLink_action()
    {
        if (!empty($_POST)) {
            
            $data           =   $_POST;
            
            $data['auid']   =   $_SESSION['auid'];
            
            $crmM           =   $this -> MODEL('crm');
            
            $return         =   $crmM -> upComLink($data);
            
            echo json_encode($return);die;
            
        }
    }
    
    /**
     * @desc 联系反馈-> 添加企业备注
     */
    function remarkCom_action()
    {
        if (!empty($_POST)) {
            
            $data           =   $_POST;
            
            $data['auid']   =   $_SESSION['auid'];
            
            $crmM           =   $this -> MODEL('crm');
            
            $return         =   $crmM -> remarkCom($data);
            
            echo json_encode($return);die;
            
        }
    }
    
    /**
     * @desc 客户管理 -> 修改账号密码 
     */
    function upPassword_action() {
        
        $crmM       =   $this -> MODEL("crm");
        
        $postData   =   $_POST;
        
        $result     =   $crmM -> upPassword($postData);
        
        echo json_encode($result);die;
           
    }
    
    /**
     * @desc 客户管理->添加/修改跟进记录
     */
    function addFollow_action()
    {
        if (!empty($_POST)) {
            
            $data           =   $_POST;
            
            $data['uid']    =   $_POST['uid'] ? $_POST['uid'] : $_POST['comid'];
            
            $data['auid']   =   $_SESSION['auid'];
            
            $crmM           =   $this -> MODEL('crm');
            
            $return         =   $crmM -> addFollow($data);
            
            echo json_encode($return);die;
        }
    }
    
    /**
     * @desc 客户管理 -> 短信模板选择 
     */
    function getMsgTpl_action() {
        
        if (!empty($_POST)) {

            $crmM   =   $this->MODEL('crm');
            
            $data   =   $_POST;
            
            $data['auid']   =   $_SESSION['auid'];
            
            $return =   $crmM -> getMsgTpl($data);
             
            echo json_encode($return);die;
        }
    }
    
    /**
     * @desc 客户管理->快捷发送短信
     */
    function sendMsg_action(){
        
        if (!empty($_POST)) {
            
            $crmM   =   $this->MODEL('crm');
            
            $data   =   $_POST;
            
            $data['auid']   =   $_SESSION['auid'];
            
            $return =   $crmM -> sendCrmMsg($data);
            
            echo json_encode($return);die;
        }
    }
    
    /**
     * @desc 客户管理详细页面，点击企业相关功能，跳转企业会员中心
     * @param  $_GET['type']，跳转招聘统计分析页面
     */
    function Imitate_action(){
        
        $userinfoM  =  $this->MODEL('userinfo');
        
        $member     =  $userinfoM -> getInfo(array('uid'=> intval($_GET['uid'])),array('field'=>'`uid`,`username`,`salt`,`email`,`password`,`usertype`,`did`'));
        
        $this -> cookie->unset_cookie();
        
        $this -> cookie->add_cookie($member['uid'],$member['username'],$member['salt'],$member['email'],$member['password'],2,1,$member['did']);
        
        $typeStr 	=	trim($_GET['type']);
        
        $url		=	'';
        
        if(!empty($typeStr)){
            
            if ($typeStr == 'job') {
                
                $url = 'index.php?c='.$typeStr;
            }else{
                
                $url = 'index.php?c='.$typeStr;
            }
            
        }
        
        header('Location: '.$this->config['sy_weburl'].'/member/'.$url);
    }
    
    function setUserLogSearch()
    {
        $timeArr    =   array('1' => '1分钟内', '2' => '1-2分钟内', '3' => '2-5分钟内', '4' => '5分钟以上');
        $operaArr   =   array('1' => '基本信息', '2' => '账户认证', '3' => '职位相关', '4' => '财务相关');
        $statusArr  =   array('1' => '未操作', '2' => '操作完成', '3' => '操作失败');
        $this->yunset(array('timeArr' => $timeArr, 'operaArr' => $operaArr, 'statusArr' => $statusArr));
    }
    
    /**
     * @desc 客户行为日志查询
     */
    function userLog_action()
    {
        $this->setUserLogSearch();

        $LogM   =   $this -> MODEL('log');

        $adminM =   $this->MODEL('admin');
        $power  =  $adminM -> getPower(array('uid'=>$_SESSION['auid']));
        
        $this ->  yunset('power', $power['power']);
        
        $comM   =   $this -> MODEL('company');
        
        $cWhere['crm_uid']  =   intval($_SESSION['auid']);
        
        $typeStr    =   intval($_GET['ctype']);
        $keywordStr =   trim($_GET['keyword']);
        
        if(!empty($keywordStr)){
            if($typeStr ==  1){
                
                $cWhere['name'] =   array('like', $keywordStr);
            }elseif ($typeStr == 2){
                
                $cWhere['uid']  =   array('like', $keywordStr);
            }
            
            $urlarr['ctype']    =   $typeStr;
            $urlarr['keyword']  =   $keywordStr;
        }
        
        $cWhere['orderby']      =   'lastupdate,DESC';
        $comArr =   $comM -> getList($cWhere, array('field' => '`uid`,`name`'));
        
        foreach ($comArr['list'] as $val) {
            $comids[]   =   $val['uid'];
        }
        
        $where['usertype']  =   '2';
        $where['uid']       =   array('in', pylode(',', $comids));
        
        if ($_GET['opera']) {
            $opera  =   intval($_GET['opera']);
            
            if($opera==1){
                
                $where['PHPYUNBTWSTART_A']   =   '';
                $where['opera'][]	=	array('=', '10', 'OR');
                $where['opera'][]	=	array('=','11','OR');
                $where['PHPYUNBTWEND_A']     =   '';
            }else if($opera==2){
                $where['PHPYUNBTWSTART_A']   =   '';
                $where['opera'][]	=	array('=', '12', 'OR');
                $where['opera'][]	=	array('=','13','OR');
                $where['PHPYUNBTWEND_A']     =   '';
            }else if($opera==3){
                $where['PHPYUNBTWSTART_A']   =   '';
                $where['opera'][]	=	array('>', '30', 'AND');
                $where['opera'][]	=	array('<','39','AND');
                $where['PHPYUNBTWEND_A']     =   '';
            }else if($opera==4){
                $where['PHPYUNBTWSTART_A']   =   '';
                $where['opera'][]	=	array('>', '40', 'AND');
                $where['opera'][]	=	array('<','49','AND');
                $where['PHPYUNBTWEND_A']     =   '';
            }
            $urlarr['opera']=   $opera;
        }
        
        if ($_GET['times']) {
            
            $times  =   intval($_GET['times']);
            
            if ($times == 1) {
                
                $where['second']    =   array('<', 60);
            }elseif ($times == 2){
                
                $where['PHPYUNBTWSTART_B']    =   '';
                $where['second'][]  =	array('>=',60,'AND');
                $where['second'][]	=	array('<',120,'AND');
                $where['PHPYUNBTWEND_B']    =   '';
            }elseif ($times == 3){
                
                $where['PHPYUNBTWSTART_B']    =   '';
                $where['second'][]  =	array('>=',120,'AND');
                $where['second'][]	=	array('<',300,'AND');
                $where['PHPYUNBTWEND_B']    =   '';
            }elseif ($times == 4){
                
                $where['second']    =   array('>=', 300);
            }
            
            $urlarr['times']        =   $times;
        }
        
        if ($_GET['status']) {
            $status =   intval($_GET['status']);
            
            if($status == 1){
                
                $where['status']	=	0;
            }else if($status == 2){

                $where['PHPYUNBTWSTART_C']       =    '';
                $where['status'][]	=	array('=','1','OR');
                $where['status'][]	=	array('=','10','OR');
                $where['status'][]	=	array('=','11','OR');
                $where['status'][]	=	array('=','12','OR');
                $where['PHPYUNBTWEND_C']    =   '';
            }else{
                
                $where['status']	=	2;
            }
            
            $urlarr['status']       =   $status;
        }
        

        $urlarr['page']     =   '{{page}}';
        $urlarr['c']        =   'userLog';
        $pageurl            =   Url($_GET['m'], $urlarr, 'admin');

        $pageM  =   $this->MODEL('page');
        $pages  =   $pageM->pageList('user_log', $where, $pageurl, $_GET['page']);

        if ($pages['total'] > 0) {
            if ($_GET['order']) {
                
                $where['orderby']   =   $_GET['t'].','.$_GET['order'];
                $urlarr['order']    =   $_GET['order'];
                $urlarr['t']        =   $_GET['t'];
            } else {
                
                $where['orderby']   =   'timeout';
            }
            $where['limit']         =   $pages['limit'];
            $rows                   =   $LogM->getUserLogList($where, array('utype' => 'admin'));
        }
        $this->yunset('rows', $rows);
        $this->yuntpl(array('admin/crm_customer_log'));
    }
    
    /**
     * @desc 客户动态：查询用户行为记录
     */
    function ajaxLog_action() {
        
        if ($_GET['uid']) {
            
            $uid    =   intval($_GET['uid']);
            
            $logM   =   $this->MODEL('log');
            
            $where  =   array(
                'uid'       =>  $uid,
                'usertype'  =>  2,
                'second'    =>  array('>', 10),
                'limit'     =>  10,
                'orderby'   =>  'timein, DESC'
            );
            
            $logs   =   $logM -> getUserLogList($where, array('utype' => 'crm'));
            
            if (!empty($logs) && is_array($logs)) {
                
                $html       =   '';
                foreach ($logs as $k => $v) {
                    
                    $html   .=  '<li>';
                    $html   .=  $v['time'].'访问了  《'.$v['urlPage'].'》 页面，滞留时间：'.$v['seconds'];    
                    $html   .=  '</li>';
                    
                }
                
                echo $html;
            }
        }
    }
    
    /**
     * @desc CRM-我的客户列表:（统计数量）
     */
    function getComNum_action(){
        $crmM   =   $this->MODEL('crm');
        echo $crmM -> getMyCustomerNum(array('crm_uid' => $_SESSION['auid']));
    }

}
?>